package generic.no1;

import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Scanner;

public class ArrayMinMaxCalculator {
	public static <T extends Comparable<T>> void calculateMinMax(T[] array) {
		if (array == null || array.length == 0) {
			System.out.println("数组为空");
			return;
		}
		T min = array[0];
		T max = array[0];
		for (int i = 1; i < array.length; i++) {
			if (array[i].compareTo(min) < 0) {
				min = array[i];
			}
			if (array[i].compareTo(max) > 0) {
				max = array[i];
			}
		}
		System.out.println("最小值: " + min);
		System.out.println("最大值: " + max);
	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		LinkedList<Integer> linkedList = new LinkedList<>();
		System.out.println("请输入数组元素：(输入其他字符退出输入)");
		while (true) {
			try {
				linkedList.add(scanner.nextInt());
			} catch (InputMismatchException inputMismatchException) {
				break;
			}
		}
		calculateMinMax(linkedList.toArray(new Integer[0]));
	}
}
